package com.walker.taogong.test;

import java.util.List;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.walker.taogong.dal.UserDal;
import com.walker.taogong.datamodel.User;

public class Main implements BundleActivator
{

    /** Logger. */
    private static Logger log = LoggerFactory
            .getLogger(Main.class);
    
    private static BundleContext context;

    private UserDal userDal;

    static BundleContext getContext()
    {
        return context;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
     * )
     */
    @Override
    public void start(BundleContext bundleContext) throws Exception
    {
        Main.context = bundleContext;
        // 启动HibernateInitializer服务

    }
    
    
    /**
     * 组件启动初期化
     */
    protected void activate(ComponentContext cc) throws Exception
    {
        log.info("starting main component");
        
        List<User> users = this.userDal.getUserList();
        
        for(User user : users)
        {
            log.info("the name is " + user.getUserName());
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
     */
    @Override
    public void stop(BundleContext bundleContext) throws Exception
    {
        Main.context = null;
    }


    public void setUserDal(UserDal userDal)
    {
        this.userDal = userDal;
    }

}
